﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Lotto.Core
{
    public partial class LotteryNumberCtrl : UserControl
    {
        /// <summary>
        /// Gets or sets the lottery number's value
        /// </summary>
        public int Value
        {
            get { return this.upDown.SelectedIndex; }
            set { this.upDown.SelectedIndex = value; }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        public LotteryNumberCtrl()
        {
            InitializeComponent();

            this.SizeChanged += new SizeChangedEventHandler(LotteryNumberCtrl_SizeChanged);

            // fill with valid numbers
            for (int i = 1; i <= 49; i++)
            {
                TextBlock numberTextBlock = new TextBlock();
                numberTextBlock.Text = i.ToString();

                this.upDown.Items.Add(numberTextBlock);
            }

            this.upDown.SelectedIndex = 0;
        }

        private void LotteryNumberCtrl_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            this.ellipseGeometry.RadiusX = this.LayoutRoot.ActualWidth / 2.0 - 10;
            this.ellipseGeometry.RadiusY = this.LayoutRoot.ActualHeight / 2.0 - 10;
            this.ellipseGeometry.Center = new Point(this.LayoutRoot.ActualWidth / 2.0, this.LayoutRoot.ActualHeight / 2.0);
        }
    }
}
